<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    console.log("开始连接")

    // Create WebSocket connection.
    const socket = new WebSocket("ws://localhost:9000");

    // Connection opened
    socket.addEventListener("open", function () {
        socket.send(JSON.stringify({code: 1, name: 'xiaoming'}));
    });

    // Listen for messages
    socket.addEventListener("message", function (event) {
        console.log("Message from server ", event.data);
    });
</script>
</html>